import request from '@/utils/request'

// 查询设备类型列表
export function listSbtype(query) {
  return request({
    url: '/sbtz/sbtype/list',
    method: 'get',
    params: query
  })
}

// 查询设备类型详细
export function getSbtype(typeCode) {
  return request({
    url: '/sbtz/sbtype/' + typeCode,
    method: 'get'
  })
}

// 新增设备类型
export function addSbtype(data) {
  return request({
    url: '/sbtz/sbtype',
    method: 'post',
    data: data
  })
}

// 修改设备类型
export function updateSbtype(data) {
  return request({
    url: '/sbtz/sbtype',
    method: 'put',
    data: data
  })
}

// 删除设备类型
export function delSbtype(typeCode) {
  return request({
    url: '/sbtz/sbtype/' + typeCode,
    method: 'delete'
  })
}

export function apiBindChildren(data) {
  // data = { parentType: string, childTypes: string[] }
  return request({
    url: '/sbtz/sbtype/edges',
    method: 'put',
    data
  })
} 
 
export function apiBindParent(data) {
  return request({
    url: '/sbtz/sbtype/bindParent',
    method: 'post',
    data,
  });
}

// 查询某类型的父/子绑定
export function apiGetRelations(params) {
  // GET /sbtz/sbtype/relation/{typeCode}
  return request({
    url: `/sbtz/sbtype/relation/${params.typeCode}`,
    method: 'get',
  });
}

// 一次性保存父/子绑定
export function apiSaveRelations(data) {
  // POST /sbtz/sbtype/relation/save
  // body: { typeCode, parentTypes:[], childTypes:[] }
  return request({
    url: '/sbtz/sbtype/relation/save',
    method: 'post',
    data,
  });
}

// 更新设备台数
export function updateDeviceCount(data) {
  return request({
    url: '/sbtz/sbtype/updateDeviceCount',
    method: 'post',
    data: data
  })
}